#ifndef GAMMAMANAGERLOCATION_H
#define GAMMAMANAGERLOCATION_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDBusInterface>
#include <QObject>
#include <QTimer>

#include "clib-syslog.h"
#include "gamma-manager-define.h"
#include "QGSettings/qgsettings.h"
#include "gamma-manager-helper.h"
#include "pingpongtest.h"

class GmLocation:public QObject
{
    Q_OBJECT
public:
    GmLocation(QObject *parent = nullptr);
    ~GmLocation();
    void start();
    void setIpAddresses(QStringList &addresses);//for unit test
    void setGsettings(QGSettings *settings);
public Q_SLOTS:
   /* 初始化目前只有网络接口初始化的监控，如果该接口初始化失败，下个timeout继续初始化。
      如果初始化成功，则链接信号，继续工作。
    */
    void doNetWorkInterfaceTimeOut();
    void doNetworkStateCanged(uint state);
    void doNAMFinished(QNetworkReply *reply);
    void getLocationByHttp();



    void TestPingPongBall(QStringList url);
private:
    void setLocation(double lon, double lat);
private:
    bool                     m_initState;
    int                      m_lastNetworkState;
    int                      m_urlChangeTimes;

    QTime                    m_connectTime;
    QSizeF                   m_location;
    QStringList              m_urlList;

    QTimer                  *m_pTimer;
    QDBusInterface          *m_pNetworkBus;
    QNetworkAccessManager   *m_NAM;
    GmHelper                *m_pGmHelper;
    QGSettings              *m_pSettings;
    PingPongTest            *m_pPingPongTest;
};

#endif // GAMMAMANAGERLOCATION_H
